
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>8、Comparable(比较器) - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>8、Comparable(比较器) - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">Java 中的 `Comparable` 接口主要作用是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`Comparable` 接口用于定义对象之间的自然顺序比较规则，使得对象具有可比性，从而能够进行排序和比较操作。</div>
          </div>
          <div class="card-source">来源: 文档引言及「1. Comparable 接口概述」部分</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">`Comparable` 接口位于哪个包中，并且它包含了哪个必须实现的方法？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`Comparable` 接口位于 `java.lang` 包中，并且只包含一个必须实现的方法，即 `compareTo()`。</div>
          </div>
          <div class="card-source">来源: 1. Comparable 接口概述</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">`compareTo()` 方法的返回值有几种情况，它们分别代表什么比较结果？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">返回负整数表示当前对象小于参数对象；返回零表示当前对象等于参数对象；返回正整数表示当前对象大于参数对象。</div>
          </div>
          <div class="card-source">来源: 4. compareTo() 方法的返回值</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">什么是对象的“自然顺序”？请举例说明。</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">自然顺序是指对象在没有外部干预的情况下所具有的默认顺序。例如，整数的自然顺序是升序排列，字符串的自然顺序是按字典顺序排列。</div>
          </div>
          <div class="card-source">来源: 3. Comparable 接口的自然顺序</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">要让一个自定义类实现 `Comparable` 接口，需要完成哪两个主要步骤？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">第一步是在类声明中声明实现 `Comparable` 接口（例如：`class MyClass implements Comparable<MyClass>`）；第二步是实现 `compareTo()` 方法，编写具体的比较逻辑。</div>
          </div>
          <div class="card-source">来源: 2. 实现 Comparable 接口的步骤</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">在哪些常见的 Java 应用场景中会使用到 `Comparable` 接口？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`Comparable` 接口广泛应用于集合类（如 `TreeSet`、`TreeMap`）和排序方法（如 `Arrays.sort()`）中的元素比较和排序操作。</div>
          </div>
          <div class="card-source">来源: 5. Comparable 接口的应用场景</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">`Comparable` 接口和 `Comparator` 接口的主要区别是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`Comparable` 接口用于定义对象的自然顺序，而 `Comparator` 接口用于提供一个外部的比较器来对对象进行排序，两者使用场景不同。</div>
          </div>
          <div class="card-source">来源: 7. Comparable 接口与 Comparator 接口的区别</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">在文档提供的 `Student` 类示例中，`compareTo()` 方法是如何实现按学生ID升序排列的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">通过 `return this.id - other.id;` 这行代码实现。当 `this.id` 小于 `other.id` 时，结果为负数；相等时为零；大于时为正数，从而实现了按 ID 升序排列。</div>
          </div>
          <div class="card-source">来源: 6. Comparable 接口的实现示例</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">当一个类的集合（如 `List<Student>`）中的元素实现了 `Comparable` 接口后，可以使用哪个类的哪个静态方法来对其进行排序？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">可以使用 `java.util.Collections` 类的 `sort()` 静态方法（`Collections.sort()`）对集合进行排序。</div>
          </div>
          <div class="card-source">来源: 6. Comparable 接口的实现示例</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
